package com.lcredu.aop.aspectj;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @author 黎长容
 * @date 2025-07-15 16:45
 * 切面类
 */
@Aspect
@Component
public class UsbInterfaceAspect {

//    @Before(value = "execution(public void com.lcredu.aop.aspectj.Phone.work())||execution(public void com.lcredu.aop.aspectj.Camera.work())")
//    public void before(JoinPoint joinPoint) {
//        Signature signature = joinPoint.getSignature();
//        System.out.println("before--前置通知--启动...得到目标方法" + signature.getName());
//    }

    //也可以对接口进行切入
    @Before(value = "execution(public void com.lcredu.aop.aspectj.UsbInterface.*(..))")
    public void before(JoinPoint joinPoint) {
        Signature signature = joinPoint.getSignature();
        System.out.println("before--前置通知--启动...得到目标方法" + signature.getName());
    }

    @AfterReturning(value = "execution(public void com.lcredu.aop.aspectj.UsbInterface.*(..))")
    public void afterReturn(JoinPoint joinPoint) {
        Signature signature = joinPoint.getSignature();
        System.out.println("afterReturn--返回通知--启动...得到目标方法" + signature.getName());
    }


    @AfterThrowing(value = "execution(public void com.lcredu.aop.aspectj.UsbInterface.*(..))")
    public void afterThrowing(JoinPoint joinPoint) {
        Signature signature = joinPoint.getSignature();
        System.out.println("afterThrowing--异常通知--启动...得到目标方法" + signature.getName());
    }

    @After(value = "execution(public void com.lcredu.aop.aspectj.UsbInterface.*(..))")
    public void after(JoinPoint joinPoint) {
        Signature signature = joinPoint.getSignature();
        System.out.println("after--最终通知--启动...得到目标方法" + signature.getName());
    }
}
